package com.comlan.installer;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

import org.apache.http.protocol.HttpService;

import com.comlan.installer.InstallerService.PackageInstallObserver;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Message;
import android.test.AndroidTestCase;
import android.text.GetChars;
import android.util.Log;

public class TestUtil extends AndroidTestCase{
	private static final String TAG = "test";
	private static final String PATH_APP_INSTALL = "/data/data/com.comlan.mterm.tms/app/install/"; //"/sdcard/apk/";
	class PackageInstallObserver extends IPackageInstallObserver.Stub {

		public void packageInstalled(String packageName, int returnCode) {
		      	
		}
	}
	public void testAutoInstall(){
//		PackageManager pm = getContext().getPackageManager();
//		int installFlags = 0;
//		PackageInstallObserver observer = new PackageInstallObserver();
//		CheckApkReceiver.updateInstall(getContext(), CheckApkReceiver.APK_PACKAGE_NAME_MTERM);
		//Log.d("test", "time = " + System.currentTimeMillis());
		//CheckApkReceiver.freshInstall(getContext(), CheckApkReceiver.APK_PACKAGE_NAME_MTERM);
//		CheckApkReceiver.isInstallSucceed(getContext(), "com.comlan.mterm");
	}
	
	public void testBackup(){
		CheckApkReceiver.updateInstall(getContext(), CheckApkReceiver.APK_PACKAGE_NAME_MTERM);
	}
	
	public void testSp() throws IOException{
		File file = new File("data/data/com.comlan.mterm.tms/shared_prefs/test.xml");
		if(file == null || file.length()==0) return;
//		FileInputStream fis = new FileInputStream(file);
//		byte[] buffer = new byte[1024];
//		fis.read(buffer);
//		Log.d(TAG, new String(buffer));
		file.renameTo(new File("data/data/" + getContext().getPackageName() + "/shared_prefs/test.xml"));
		SharedPreferences sp = getContext().getSharedPreferences("test", Context.MODE_PRIVATE);
		String res = sp.getString("aaa", "");
		Log.d(TAG, "res = " + res);
		
	}
}
    